package com.qf.homework.dao;

import com.qf.homework.dao.StudentsDao;
import com.qf.homework.entity.Students;
import com.qf.homework.util.StudentsDaoUtil;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class StudentsDao1 {

    @Test
    public void test2() throws IOException {
        SqlSession sqlSession = StudentsDaoUtil.reSess();
        StudentsDao studentsDao = sqlSession.getMapper(StudentsDao.class);
        int i = studentsDao.selectAll();
        int v = (int) (Math.random() * i);
        List<Students> select = studentsDao.select();
        Students students = select.get(v);
        System.out.println(students);
        int update = studentsDao.update(v+1);
        System.out.println(update);
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public void test3() throws IOException {
        SqlSession sqlSession = StudentsDaoUtil.reSess();
        StudentsDao mapper = sqlSession.getMapper(StudentsDao.class);
        int i = mapper.update1();
        System.out.println(i);
        sqlSession.commit();
    }
}
